<template>
  <div class="content-wraper">
    <div class="search-box">
      <el-form label-width="100px" :inline="true">
        <el-form-item label="招标名称">
          <el-input v-model="bidName" />
        </el-form-item>
        <el-form-item label="中标单位">
          <el-input v-model="supplierInfoName" />
        </el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
        <el-button type="warning" icon="el-icon-refresh" @click="reset()">重置</el-button>
      </el-form>
    </div>
    <div class="detail">
      <com-table :data="dataList" :columns="columns" :total="total" @pageChange="pageChange">
        <template v-slot:biBidStartTime="{row: {biBidStartTime}}">
          {{ dateFormat(biBidStartTime) }}
        </template>
      </com-table>
    </div>
    <add-bid-info
      :show-modal.sync="showModal"
      :opt-type="optType"
      :data="unitDetail"
      @freshList="search"
    />
  </div>
</template>

<script>
import { getBidOpenFinishInfoList } from '@/api/bigManage'
import moment from 'moment'
import { getDictName } from '@/utils/comm'
import addBidInfo from './addBidInfo.vue'
import { bidInfoMode, bidInfoType, workflowStatus } from '@/utils/dicData'
export default {
  name: 'BidInfo',
  components: {
    addBidInfo
  },
  data() {
    return {
      bidName: '',
      supplierInfoName: '',
      getDictName,
      bidInfoMode,
      bidInfoType,
      workflowStatus,

      dataList: [],
      total: 0,
      pageParams: {
        pageNum: 1,
        pageSize: 10
      },
      showModal: false,
      optType: 'add',
      unitDetail: {},
      columns: [
        {
          label: '招标名称',
          prop: 'biName'
        },
        {
          label: '开标时间',
          prop: 'biBidStartTime',
          slot: 'biBidStartTime',
          width: '90'
        },
        {
          label: '限价金额',
          prop: 'blLimitPrice'
        },
        {
          label: '投标金额',
          prop: 'boBidPrice'
        },
        {
          label: '中标单位',
          prop: 'boBidUnit'
        },
        {
          label: '联系人',
          prop: 'boContactPerson'
        },
        {
          label: '联系电话',
          prop: 'boContactPhone'
        },
        {
          label: '备注',
          prop: 'boRemark'
        }
      ]
    }
  },
  mounted() {
    this.getDataList()
  },
  methods: {
    dateFormat(data) {
      if (data) {
        return moment(data).format('YYYY-MM-DD')
      } else {
        return ''
      }
    },
    pageChange(data) {
      this.pageParams = data
      this.getDataList()
    },
    getDataList() {
      this.pageParams.name = this.name
      const params = {
        ...this.pageParams,
        bidName: this.bidName,
        supplierInfoName: this.supplierInfoName
      }
      getBidOpenFinishInfoList(params).then(res => {
        const { data, total } = res.data || {}
        if (data) {
          this.dataList = data
          this.total = total - 0
        }
      })
    },
    search() {
      this.pageParams.pageNum = 1
      this.getDataList()
    },
    reset() {
      this.bidName = ''
      this.supplierInfoName = ''
    }

  }
}
</script>

<style lang="scss" scoped>
.search-box {
  height: 50px;
}
.detail{
  height: calc(100% - 50px);
}
</style>
